﻿using System;
using System.Windows;
using System.Windows.Browser;
using ResourceExtension.Abstract;
using System.IO;

namespace ResourceExtension.Implementation
{
    public class CultureResourceBehavior : AbstractResourceBehavior<CultureResourceOptions>
    {
        #region Overrides of AbstractResourceBehavior<CultureResourceOptions>

        protected override string GetManifestResourceName(string assemblyName, Type resourceType, CultureResourceOptions options)
        {
            return string.Format("{0}.{1}.resources",resourceType.FullName,options.ToQuery());
        }

        protected override string GetFilePath(string assemblyName, CultureResourceOptions options)
        {

            Uri uri = Application.Current.Host.Source;

            if (uri.Scheme == "file")
            {
                /*string path = Path.GetDirectoryName(uri.LocalPath);
                path = path.Replace('\\', '/');
                return string.Format("file://{0}/{2}/{1}.resources.dll",
                     path,
                     assemblyName,
                     options.ToQuery());*/

                throw new NotSupportedException();
            }
            else
            {
                string absolute = uri.AbsoluteUri;

                string path = absolute.Remove(absolute.Length - uri.LocalPath.Length);

                return string.Format("{0}/ClientBin/{2}/{1}.resources.dll",
                                     path,
                                     assemblyName,
                                     options.ToQuery());
            }
        }

        #endregion
    }
}
